package com.activitycode.activity.find;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

import com.activitycode.fragment.PetFriendFragment1;
import com.activitycode.fragment.PetFriendFragment2;
import com.activitycode.util.CommConstant;
import com.activitycode.view.TitleBarView;
import com.duostec.zhuyue.pets.R;

public class PetsFriendDirActivity extends FragmentActivity {
	private TitleBarView titleBarView;
	private ImageButton titleBack;
	private ViewPager pager;
	private MyPagerAdapter adapter;	
	private List<Drawable> drawableList = new ArrayList<Drawable>();
	private PetFriendFragment1 petFriendFragment1;
	private PetFriendFragment2 petFriendFragment2;
  	private boolean isAtten;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ui_petfrienddir);
		
		initView();
		initData();
	}
	
	private void initView(){		
		titleBack = (ImageButton) this.findViewById(R.id.title_petfrienddir_back);
		titleBack.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				finish();
			}
			
		});
		titleBarView = (TitleBarView) this.findViewById(R.id.title_petfrienddi_titleBarView1);
		pager = (ViewPager) this.findViewById(R.id.petfrienddi_viewpager);
	}
	
	private void initData(){
		isAtten = getIntent().getBooleanExtra(CommConstant.INTENT_TYPE, true);
		pager.setAdapter(new MyPagerAdapter(this.getSupportFragmentManager(),this));
		drawableList.add(this.getResources().getDrawable(R.drawable.style_petfrienddir_title1));
		drawableList.add(this.getResources().getDrawable(R.drawable.style_petfrienddir_title2));
		titleBarView.init(this, drawableList, pager, 0);
	}
	
	
	public class MyPagerAdapter extends FragmentPagerAdapter {
		Context context;
		public MyPagerAdapter(FragmentManager fm,Context context) {
			super(fm);
			this.context = context;
		}

		private final String[] titles = { "", "" };

		@Override
		public CharSequence getPageTitle(int position) {
			return titles[position];
		}

		@Override
		public int getCount() {
			return titles.length;
		}

		@Override
		public Fragment getItem(int position) {
			switch (position) {
			case 0:
				if (petFriendFragment1 == null) {
					petFriendFragment1 = new PetFriendFragment1(true);
				}
				return petFriendFragment1;	
			case 1:
				if (petFriendFragment2 == null) {
					petFriendFragment2 = new PetFriendFragment2(true);
				}
				return petFriendFragment2;
					
			default:
				return petFriendFragment1;
			}
		}

	}
	
	
	
	
}
